package org.ielse.frame.util;

import android.annotation.SuppressLint;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@SuppressLint("SimpleDateFormat")
public class DateUtil {

	public static final String yyyy_MM_dd_HH_mm_ss = "yyyy\u5e74MM\u6708dd\u65e5 HH:mm:ss";
	public static final String yyyyMMddHHmmss = "yyyyMMddHHmmss";
	public static final String HHmmss = "HHmmss";
	public static final String dd = "dd";
	public static final String MM_dd_ = "MM\u6708dd\u65e5";

	private static final SimpleDateFormat sdf = new SimpleDateFormat();

	public static Date parse(String date, String pattern) {
		try {
			sdf.applyPattern(pattern);
			return sdf.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}

	public static String format(Date date, String pattern) {
		sdf.applyPattern(pattern);
		return sdf.format(date);
	}

	public static String convert(String string, String oldPattern, String newPattern) {
		return format(parse(string, oldPattern), newPattern);
	}

}
